<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Introduction - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.http.client.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.http.client.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.http.html">Zend_Http</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.http.html">Zend_Http</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.http.client.advanced.html">Zend_Http_Client - Advanced Usage</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.http.client" class="section"><div class="info"><h1 class="title">Introduction</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Http_Client</span> provides an easy interface for preforming Hyper-Text
        Transfer Protocol (HTTP) requests. <span class="classname">Zend_Http_Client</span> supports most
        simple features expected from an <acronym class="acronym">HTTP</acronym> client, as well as some more
        complex features such as <acronym class="acronym">HTTP</acronym> authentication and file uploads. Successful
        requests (and most unsuccessful ones too) return a <span class="classname">Zend_Http_Response</span>
        object, which provides access to the response&#039;s headers and body (see
        <a href="zend.http.response.html" class="link">this section</a>).
    </p>

    <div class="section" id="zend.http.client.usage"><div class="info"><h1 class="title">Using Zend_Http_Client</h1></div>
        

        <p class="para">
            The class constructor optionally accepts a URL as its first parameter
            (can be either a string or a <span class="classname">Zend_Uri_Http</span> object), and an array
            or <span class="classname">Zend_Config</span> object containing configuration options. Both can
            be left out, and set later using the setUri() and setConfig() methods.

            <div class="example" id="zend.http.client.introduction.example-1"><div class="info"><p><b>Example #1 Instantiating a Zend_Http_Client Object</b></p></div>
                

                <pre class="programlisting brush: php">
$client = new Zend_Http_Client(&#039;http://example.org&#039;, array(
    &#039;maxredirects&#039; =&gt; 0,
    &#039;timeout&#039;      =&gt; 30));

// This is actually exactly the same:
$client = new Zend_Http_Client();
$client-&gt;setUri(&#039;http://example.org&#039;);
$client-&gt;setConfig(array(
    &#039;maxredirects&#039; =&gt; 0,
    &#039;timeout&#039;      =&gt; 30));

// You can also use a Zend_Config object to set the client&#039;s configuration
$config = new Zend_Config_Ini(&#039;httpclient.ini&#039;, &#039;secure&#039;);
$client-&gt;setConfig($config);
</pre>

            </div>

            <blockquote class="note"><p><b class="note">Note</b>: 
                <p class="para">
                    <span class="classname">Zend_Http_Client</span> uses
                    <span class="classname">Zend_Uri_Http</span> to validate URLs. This means
                    that some special characters like the pipe symbol (&#039;|&#039;) or the
                    caret symbol (&#039;^&#039;) will not be accepted in the URL by default.
                    This can be modified by setting the &#039;allow_unwise&#039; option of
                    <span class="classname">Zend_Uri</span> to &#039;<b><tt>TRUE</tt></b>&#039;. See <a href="zend.uri.chapter.html#zend.uri.validation.allowunwise" class="link">this section</a> for more
                    information.
                </p>
            </p></blockquote>
        </p>
    </div>

    <div class="section" id="zend.http.client.configuration"><div class="info"><h1 class="title">Configuration Parameters</h1></div>
        

        <p class="para">
            The constructor and setConfig() method accept an associative array
            of configuration parameters, or a <span class="classname">Zend_Config</span> object. Setting
            these parameters is optional, as they all have default values.

            <table id="zend.http.client.configuration.table" class="doctable table"><div class="info"><caption><b>Zend_Http_Client configuration parameters</b></caption></div>
                

                
                    <thead valign="middle">
                        <tr valign="middle">
                            <th>Parameter</th>
                            <th>Description</th>
                            <th>Expected Values</th>
                            <th>Default Value</th>
                        </tr>

                    </thead>


                    <tbody valign="middle" class="tbody">
                        <tr valign="middle">
                            <td align="left">maxredirects</td>
                            <td align="left">Maximum number of redirections to follow (0 = none)</td>
                            <td align="left">integer</td>
                            <td align="left">5</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">strict</td>

                            <td align="left">
                                Whether perform validation on header names. When set to
                                <b><tt>FALSE</tt></b>, validation functions will be skipped.
                                Usually this should not be changed
                            </td>

                            <td align="left">boolean</td>
                            <td align="left"><b><tt>TRUE</tt></b></td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">strictredirects</td>

                            <td align="left">
                                Whether to strictly follow the <acronym class="acronym">RFC</acronym> when
                                redirecting (see <a href="zend.http.client.advanced.html#zend.http.client.redirections" class="link">this section</a>)
                            </td>

                            <td align="left">boolean</td>
                            <td align="left"><b><tt>FALSE</tt></b></td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">useragent</td>
                            <td align="left">User agent identifier string (sent in request headers)</td>
                            <td align="left">string</td>
                            <td align="left">&#039;Zend_Http_Client&#039;</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">timeout</td>
                            <td align="left">Connection timeout (seconds)</td>
                            <td align="left">integer</td>
                            <td align="left">10</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">httpversion</td>
                            <td align="left">HTTP protocol version (usually &#039;1.1&#039; or &#039;1.0&#039;)</td>
                            <td align="left">string</td>
                            <td align="left">&#039;1.1&#039;</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">adapter</td>

                            <td align="left">
                                Connection adapter class to use (see <a href="zend.http.client.adapters.html" class="link">this section</a>)
                            </td>

                            <td align="left">mixed</td>
                            <td align="left">&#039;Zend_Http_Client_Adapter_Socket&#039;</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">keepalive</td>

                            <td align="left">
                                Whether to enable keep-alive connections with the server. Useful and
                                might improve performance if several consecutive requests to the
                                same server are performed.
                            </td>

                            <td align="left">boolean</td>
                            <td align="left"><b><tt>FALSE</tt></b></td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">storeresponse</td>

                            <td align="left">
                                Whether to store last response for later retrieval with
                                 <span class="methodname">getLastResponse()</span>. If set to
                                <b><tt>FALSE</tt></b>
                                 <span class="methodname">getLastResponse()</span> will return
                                <b><tt>NULL</tt></b>.
                            </td>

                            <td align="left">boolean</td>
                            <td align="left"><b><tt>TRUE</tt></b></td>
                        </tr>

                        <tr valign="middle">
                            <td align="left">encodecookies</td>

                            <td align="left">
                                Whether to pass the cookie value through urlencode/urldecode.
                                Enabling this breaks support with some web servers.
                                Disabling this limits the range of values the cookies can contain.
                            </td>

                            <td align="left">boolean</td>
                            <td align="left"><b><tt>TRUE</tt></b></td>
                        </tr>

                    </tbody>
                
            </table>

        </p>
    </div>

    <div class="section" id="zend.http.client.basic-requests"><div class="info"><h1 class="title">Performing Basic HTTP Requests</h1></div>
        

        <p class="para">
            Performing simple <acronym class="acronym">HTTP</acronym> requests is very easily done using the
            request() method, and rarely needs more than three lines of code:

            <div class="example" id="zend.http.client.basic-requests.example-1"><div class="info"><p><b>Example #2 Performing a Simple GET Request</b></p></div>
                

                <pre class="programlisting brush: php">
$client = new Zend_Http_Client(&#039;http://example.org&#039;);
$response = $client-&gt;request();
</pre>

            </div>

            The request() method takes one optional parameter - the request method.
            This can be either <span class="property">GET</span>, <span class="property">POST</span>,
            <span class="property">PUT</span>, <span class="property">HEAD</span>, <span class="property">DELETE</span>,
            <span class="property">TRACE</span>, <span class="property">OPTIONS</span> or <span class="property">CONNECT</span>
            as defined by the <acronym class="acronym">HTTP</acronym> protocol

            <a href="#fnid1" name="fn1"><sup>[1]</sup></a>
              <tt class="uri">http://www.w3.org/Protocols/rfc2616/rfc2616.html</tt>
            .

            For convenience, these are all defined as class constants:
            Zend_Http_Client::GET, Zend_Http_Client::POST and so on.
        </p>

        <p class="para">
            If no method is specified, the method set by the last
             <span class="methodname">setMethod()</span> call is used. If
             <span class="methodname">setMethod()</span> was never called, the default request
            method is <b><tt>GET</tt></b> (see the above example).

            <div class="example" id="zend.http.client.basic-requests.example-2"><div class="info"><p><b>Example #3 Using Request Methods Other Than GET</b></p></div>
                

                <pre class="programlisting brush: php">
// Preforming a POST request
$response = $client-&gt;request(&#039;POST&#039;);

// Yet another way of preforming a POST request
$client-&gt;setMethod(Zend_Http_Client::POST);
$response = $client-&gt;request();
</pre>

            </div>
        </p>
    </div>

    <div class="section" id="zend.http.client.parameters"><div class="info"><h1 class="title">Adding GET and POST parameters </h1></div>
        

        <p class="para">
            Adding <b><tt>GET</tt></b> parameters to an <acronym class="acronym">HTTP</acronym> request is
            quite simple, and can be done either by specifying them as part of the URL, or by using
            the setParameterGet() method.
            This method takes the <b><tt>GET</tt></b> parameter&#039;s name as its first parameter,
            and the <b><tt>GET</tt></b> parameter&#039;s value as its second parameter.
            For convenience, the setParameterGet() method can also accept a
            single associative array of name =&gt; value <b><tt>GET</tt></b> variables - which may
            be more comfortable when several <b><tt>GET</tt></b> parameters need to be set.

            <div class="example" id="zend.http.client.parameters.example-1"><div class="info"><p><b>Example #4 Setting GET Parameters</b></p></div>
                

                <pre class="programlisting brush: php">
// Setting a get parameter using the setParameterGet method
$client-&gt;setParameterGet(&#039;knight&#039;, &#039;lancelot&#039;);

// This is equivalent to setting such URL:
$client-&gt;setUri(&#039;http://example.com/index.php?knight=lancelot&#039;);

// Adding several parameters with one call
$client-&gt;setParameterGet(array(
    &#039;first_name&#039;  =&gt; &#039;Bender&#039;,
    &#039;middle_name&#039; =&gt; &#039;Bending&#039;
    &#039;made_in&#039;     =&gt; &#039;Mexico&#039;,
));
</pre>

            </div>
        </p>

        <p class="para">
            While <b><tt>GET</tt></b> parameters can be sent with every request method, POST
            parameters are only sent in the body of POST requests. Adding POST
            parameters to a request is very similar to adding <b><tt>GET</tt></b> parameters,
            and can be done with the setParameterPost() method, which is
            similar to the setParameterGet() method in structure.

            <div class="example" id="zend.http.client.parameters.example-2"><div class="info"><p><b>Example #5 Setting POST Parameters</b></p></div>
                

                <pre class="programlisting brush: php">
// Setting a POST parameter
$client-&gt;setParameterPost(&#039;language&#039;, &#039;fr&#039;);

// Setting several POST parameters, one of them with several values
$client-&gt;setParameterPost(array(
    &#039;language&#039;  =&gt; &#039;es&#039;,
    &#039;country&#039;   =&gt; &#039;ar&#039;,
    &#039;selection&#039; =&gt; array(45, 32, 80)
));
</pre>

            </div>

            Note that when sending POST requests, you can set both <b><tt>GET</tt></b> and
            POST parameters. On the other hand, while setting POST parameters
            for a non-POST request will not trigger and error, it is useless.
            Unless the request is a POST request, POST parameters are simply
            ignored.
        </p>
    </div>

    <div class="section" id="zend.http.client.accessing_last"><div class="info"><h1 class="title">Accessing Last Request and Response</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Http_Client</span> provides methods of accessing the last request
            sent and last response received by the client object.
            <span class="classname">Zend_Http_Client-&gt;getLastRequest()</span> takes no parameters
            and returns the last <acronym class="acronym">HTTP</acronym> request sent by the client as a string.
            Similarly, <span class="classname">Zend_Http_Client-&gt;getLastResponse()</span> returns
            the last <acronym class="acronym">HTTP</acronym> response received by the client as a
            <a href="zend.http.response.html" class="link">Zend_Http_Response</a> object.
        </p>
    </div>
<div class="footnote"><a name="fnid1" href="#fn1"><sup>[1]</sup></a><span class="para footnote">
                See RFC 2616 - .
              </span></div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.http.html">Zend_Http</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.http.html">Zend_Http</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.http.client.advanced.html">Zend_Http_Client - Advanced Usage</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.http.html">Zend_Http</a></li>
  <li class="active"><a href="zend.http.client.html">Introduction</a></li>
  <li><a href="zend.http.client.advanced.html">Zend_Http_Client - Advanced Usage</a></li>
  <li><a href="zend.http.client.adapters.html">Zend_Http_Client - Connection Adapters</a></li>
  <li><a href="zend.http.cookies.html">Zend_Http_Cookie and Zend_Http_CookieJar</a></li>
  <li><a href="zend.http.response.html">Zend_Http_Response</a></li>
  <li><a href="zend.http.user-agent.html">Zend_Http_UserAgent</a></li>
  <li><a href="zend.http.user-agent-device.html">The UserAgent Device Interface</a></li>
  <li><a href="zend.http.user-agent-features.html">The UserAgent Features Adapter</a></li>
  <li><a href="zend.http.user-agent-features-wurfl.html">The WURFL UserAgent Features Adapter</a></li>
  <li><a href="zend.http.user-agent-features-device-atlas.html">The DeviceAtlas UserAgent Features Adapter</a></li>
  <li><a href="zend.http.user-agent-features-tera-wurfl.html">The TeraWurfl UserAgent Features Adapter</a></li>
  <li><a href="zend.http.user-agent-storage.html">The UserAgent Storage Interface</a></li>
  <li><a href="zend.http.user-agent-storage-session.html">The Session UserAgent Storage Adapter</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>